package com.mini.constant;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public enum KanbanDimension {

    dimension_class("dimension_class", "班次维度", 0),
    dimension_teacher("dimension_teacher", "运营专员维度", 1),
    dimension_org_group("dimension_org_group", "运营组维度", 2),
    dimension_org_dept("dimension_org_dept", "部门维度", 3),
    dimension_org_studio("dimension_org_studio", "工作室维度", 4),
    dimension_org_sku("dimension_org_sku", "SKU维度", 5),

    ;


    private String code;
    private String name;
    private int order;

    KanbanDimension(String code, String name, int order) {
        this.code = code;
        this.name = name;
        this.order = order;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public int getOrder() {
        return order;
    }


    public static KanbanDimension getByCode(String code){
        if(StringUtils.isBlank(code)){
            return null;
        }

        for(KanbanDimension kd : KanbanDimension.values()){
            if(kd.getCode().equals(code)){
                return kd;
            }
        }

        return null;
    }

    public static List<String> allOptions(){
        List<String> options = new ArrayList<>();
        for(KanbanDimension kd : KanbanDimension.values()){
            options.add(kd.getCode());
        }
        return options;
    }

    /**
     * 通过组织架构code，返回可显示的选项
     * @param level
     * @return
     */
    public static List<KanbanDimensionOption> getOptions(Boolean zhuanyuan, String level){
        List<KanbanDimensionOption> options = new ArrayList<>();

        //TODO 根据code动态设置

        //运营专员-只支持筛选班次
        if(zhuanyuan){
            options.add(new KanbanDimensionOption(KanbanDimension.dimension_class));
            return options;
        }

        if(!zhuanyuan && level == null){
            level = "";
        }

        List<KanbanDimensionOption> allOptions = new ArrayList<>();
        for(KanbanDimension kd : KanbanDimension.values()){
            allOptions.add(new KanbanDimensionOption(kd));
        }
        //非运营专员
        switch (level){
            case "7" : {
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_teacher));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_class));
                break;
            }
            case "6" : {
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_org_group));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_teacher));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_class));
                break;
            }
            case "5" : {
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_org_dept));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_org_group));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_teacher));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_class));
                break;
            }
            case "4" : {
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_org_studio));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_org_dept));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_org_group));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_teacher));
                options.add(new KanbanDimensionOption(KanbanDimension.dimension_class));
                break;
            }
            case "3" : {
                options.addAll(allOptions);
                break;
            }
            default : {
                options.addAll(allOptions);
            }
        }

        options.sort((o1,o2) -> Integer.compare(o2.getOrder(), o1.getOrder()));
        return options;

    }

    @Data
    public static class KanbanDimensionOption implements Serializable {
        private String code;
        private String name;
        private int order;

        public KanbanDimensionOption(String code, String name, int order) {
            this.code = code;
            this.name = name;
            this.order = order;
        }

        public KanbanDimensionOption(KanbanDimension kd){
            this.code = kd.getCode();
            this.name = kd.getName();
            this.order = kd.getOrder();
        }
    }
}
